from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-30 14:13:04.415828
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 30, Sep, 2021
Time: 14:13:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4336
Nobs: 430.000 HQIC: -46.9483
Log likelihood: 4764.80 FPE: 2.91594e-21
AIC: -47.2842 Det(Omega_mle): 2.37094e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.423736 0.091369 4.638 0.000
L1.Burgenland 0.105025 0.047307 2.220 0.026
L1.Kärnten -0.113476 0.023780 -4.772 0.000
L1.Niederösterreich 0.153701 0.101602 1.513 0.130
L1.Oberösterreich 0.110170 0.099676 1.105 0.269
L1.Salzburg 0.286539 0.049867 5.746 0.000
L1.Steiermark 0.035601 0.066329 0.537 0.591
L1.Tirol 0.105857 0.052409 2.020 0.043
L1.Vorarlberg -0.101787 0.047010 -2.165 0.030
L1.Wien 0.000928 0.090910 0.010 0.992
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013768 0.208611 0.066 0.947
L1.Burgenland -0.050852 0.108011 -0.471 0.638
L1.Kärnten 0.037428 0.054294 0.689 0.491
L1.Niederösterreich -0.207221 0.231976 -0.893 0.372
L1.Oberösterreich 0.494716 0.227578 2.174 0.030
L1.Salzburg 0.305665 0.113855 2.685 0.007
L1.Steiermark 0.104071 0.151442 0.687 0.492
L1.Tirol 0.313272 0.119659 2.618 0.009
L1.Vorarlberg 0.000123 0.107331 0.001 0.999
L1.Wien 0.000981 0.207564 0.005 0.996
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245257 0.046369 5.289 0.000
L1.Burgenland 0.088820 0.024008 3.700 0.000
L1.Kärnten -0.001376 0.012068 -0.114 0.909
L1.Niederösterreich 0.205496 0.051563 3.985 0.000
L1.Oberösterreich 0.157620 0.050585 3.116 0.002
L1.Salzburg 0.038886 0.025307 1.537 0.124
L1.Steiermark 0.024018 0.033662 0.713 0.476
L1.Tirol 0.066958 0.026597 2.517 0.012
L1.Vorarlberg 0.061133 0.023857 2.562 0.010
L1.Wien 0.114562 0.046136 2.483 0.013
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187512 0.045222 4.146 0.000
L1.Burgenland 0.045729 0.023414 1.953 0.051
L1.Kärnten -0.006387 0.011770 -0.543 0.587
L1.Niederösterreich 0.140973 0.050287 2.803 0.005
L1.Oberösterreich 0.318719 0.049334 6.460 0.000
L1.Salzburg 0.100924 0.024681 4.089 0.000
L1.Steiermark 0.128623 0.032829 3.918 0.000
L1.Tirol 0.076847 0.025939 2.963 0.003
L1.Vorarlberg 0.056002 0.023267 2.407 0.016
L1.Wien -0.048960 0.044995 -1.088 0.277
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206601 0.089654 2.304 0.021
L1.Burgenland -0.048545 0.046419 -1.046 0.296
L1.Kärnten -0.033352 0.023334 -1.429 0.153
L1.Niederösterreich 0.115680 0.099695 1.160 0.246
L1.Oberösterreich 0.169702 0.097805 1.735 0.083
L1.Salzburg 0.251419 0.048931 5.138 0.000
L1.Steiermark 0.075706 0.065084 1.163 0.245
L1.Tirol 0.123901 0.051425 2.409 0.016
L1.Vorarlberg 0.115505 0.046127 2.504 0.012
L1.Wien 0.027256 0.089204 0.306 0.760
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035960 0.069246 0.519 0.604
L1.Burgenland 0.020933 0.035853 0.584 0.559
L1.Kärnten 0.054730 0.018022 3.037 0.002
L1.Niederösterreich 0.207665 0.077002 2.697 0.007
L1.Oberösterreich 0.338993 0.075542 4.487 0.000
L1.Salzburg 0.047523 0.037793 1.257 0.209
L1.Steiermark -0.008478 0.050269 -0.169 0.866
L1.Tirol 0.111637 0.039720 2.811 0.005
L1.Vorarlberg 0.069309 0.035627 1.945 0.052
L1.Wien 0.122927 0.068899 1.784 0.074
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198886 0.084752 2.347 0.019
L1.Burgenland 0.012594 0.043882 0.287 0.774
L1.Kärnten -0.056766 0.022058 -2.573 0.010
L1.Niederösterreich -0.127459 0.094245 -1.352 0.176
L1.Oberösterreich 0.196145 0.092458 2.121 0.034
L1.Salzburg 0.035270 0.046256 0.762 0.446
L1.Steiermark 0.286070 0.061526 4.650 0.000
L1.Tirol 0.489229 0.048614 10.064 0.000
L1.Vorarlberg 0.078691 0.043606 1.805 0.071
L1.Wien -0.109923 0.084327 -1.304 0.192
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159651 0.092517 1.726 0.084
L1.Burgenland -0.012935 0.047902 -0.270 0.787
L1.Kärnten 0.063536 0.024079 2.639 0.008
L1.Niederösterreich 0.195899 0.102879 1.904 0.057
L1.Oberösterreich -0.123814 0.100929 -1.227 0.220
L1.Salzburg 0.233885 0.050494 4.632 0.000
L1.Steiermark 0.149181 0.067163 2.221 0.026
L1.Tirol 0.048830 0.053068 0.920 0.357
L1.Vorarlberg 0.130422 0.047600 2.740 0.006
L1.Wien 0.157451 0.092053 1.710 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479863 0.050289 9.542 0.000
L1.Burgenland -0.007707 0.026038 -0.296 0.767
L1.Kärnten -0.009288 0.013088 -0.710 0.478
L1.Niederösterreich 0.203652 0.055921 3.642 0.000
L1.Oberösterreich 0.252965 0.054861 4.611 0.000
L1.Salzburg 0.024343 0.027447 0.887 0.375
L1.Steiermark -0.021185 0.036507 -0.580 0.562
L1.Tirol 0.065241 0.028846 2.262 0.024
L1.Vorarlberg 0.060991 0.025874 2.357 0.018
L1.Wien -0.046466 0.050037 -0.929 0.353
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021049 0.082989 0.140494 0.130123 0.045459 0.075597 -0.000944 0.187252
Kärnten 0.021049 1.000000 -0.044035 0.129166 0.048607 0.071424 0.452814 -0.090238 0.089088
Niederösterreich 0.082989 -0.044035 1.000000 0.283465 0.082370 0.268069 0.030809 0.136956 0.262449
Oberösterreich 0.140494 0.129166 0.283465 1.000000 0.176790 0.288546 0.158109 0.101866 0.136504
Salzburg 0.130123 0.048607 0.082370 0.176790 1.000000 0.125324 0.057070 0.107413 0.050791
Steiermark 0.045459 0.071424 0.268069 0.288546 0.125324 1.000000 0.132766 0.091430 -0.014957
Tirol 0.075597 0.452814 0.030809 0.158109 0.057070 0.132766 1.000000 0.047007 0.119411
Vorarlberg -0.000944 -0.090238 0.136956 0.101866 0.107413 0.091430 0.047007 1.000000 -0.047204
Wien 0.187252 0.089088 0.262449 0.136504 0.050791 -0.014957 0.119411 -0.047204 1.000000